$(function(){
	
	var $name 	= $('#name');
	var $passwd = $('#passwd');
	
	$name.focus();
	
	var $btnLogin = $('#btnLogin');
	$btnLogin.click(function(){
		Login($.trim($name.val()),$.trim($passwd.val()));
	});
	
	$passwd.keydown(function(event){
		  if(event.keyCode == 13) {
			  $btnLogin.click();
		  }
	});	
	
});

//登录
function Login(name,passwd){
	var url = '/index.php/Member/login_do';
	var params = {
		'name':name,
		'passwd':passwd
	};
	
	$.post(url,params,function(data){
		if(data.success){
			var $from = $('#from');
			var from  = $.trim($from.val());
			if(from  != ''){
				location.href = from;
			}else{
				location.href = '/index.php/Member/';
			}			
		}else{
			alert('登录失败,用户名或密码错误!');
		}
	},'json');
}